package com.atguigu.yygh.hosp.controller.admin;


import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @GetMapping("/{pageNum}/{pageSize}")
    public R getHospitalPage(@PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize,
                             HospitalQueryVo hospitalQueryVo) {

        Page<Hospital> page = hospitalService.getHospitalPage(pageNum, pageSize, hospitalQueryVo);

        return R.ok().data("total", page.getTotalElements()).data("list", page.getContent());
    }


    @PutMapping("/{id}/{status}")
    public R updateStatus(@PathVariable("id") String id,
                          @PathVariable("status") Integer status) {
        hospitalService.updateStatus(id, status);
        return R.ok();
    }

    @GetMapping("/detail/{id}")
    public R getHospById(@PathVariable("id") String id){
        Hospital hospital =  hospitalService.detail(id);
        return R.ok().data("hospital", hospital);
    }
}
